﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Collections.Specialized;
using SyCODE.Component.Security;
using SyCODE.Component.DataFactory;
using SyCODE.Component;
using System.Xml;
using System.IO;
using System.Data.Common;

namespace SyCODE.Blog
{
    /// <summary>
	/// GetTopicIndex 的摘要说明
    /// </summary>
    public class GetBloggerIndex : IHttpHandler
    {
        #region IHttpHandler 成员

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            NameValueCollection nvc = new NameValueCollection(context.Request.QueryString);

			if (String.IsNullOrEmpty(nvc["page"]))
			{
                nvc.Add("page", "1");
			}
			if (String.IsNullOrEmpty(nvc["size"]))
			{
                nvc.Add("size", "20");
			}

            context.Response.Expires = 120;
            context.Response.ContentType = "text/xml";

            DBAM dbam = new DBAM();
            dbam.BuildParameters("blogger", nvc);

            XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, context.Response.ContentEncoding);
            writer.WriteStartDocument();
            writer.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='/ui/common/blogger.xsl'");

            try
            {
                dbam.ExecuteXmlTextWriter(writer, nvc);
            }
            finally
            {
                dbam.Dispose();
            }

            writer.WriteEndDocument();

            writer.Flush();
        }

        #endregion
    }
}